/**
 * The initial Class for the Plagiarism Detector. Starts setting up the system
 * for either Document Management or Document Scanning.
 * 
 * @author Chris Baillie.
 */

package application;

import java.io.*;

public class StartupManager {

	//Instance Variables
	//BufferedReader to get user input
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	//Creates a new DocumentManager to handle Documents coming in.
	DocumentManager doc = new DocumentManager();
	SearchManager search;
	
	/**
	 * Creates a new StartupManager each time the program is run. 
	 */
	public static void main(String[] args) {
		new StartupManager();		
	}
	
	/**
	 * Welcome to the program blah blah.
	 */
	public StartupManager()
	{
		System.out.println("");
		System.out.println("Welcome to the Foxtrot Plagiarism Detector.");
		System.out.println("");
		go();
	}
	
	/**
	 * Finds out what the user wants to do and acts
	 * upon it.
	 */
	public void go()
	{
		//Find out what we're doing...
		System.out.println("What would you like to do?");
		System.out.println("1. Add Documents.    2. Start a Search.");
		System.out.print("Choose:> ");
		int choice = 0;
		try {
			choice = Integer.parseInt(in.readLine());
		} catch(Exception e) {
			System.out.println("IO Exception!");
			e.printStackTrace();
		}
		switch(choice){
			case 1:
				//Add Documents to the database.
				getDocuments();
			break;
			case 2:
				//Close any DocumentManagers we used - just for tidiness!
				doc.finalize();
				//Start a Search
				search = new SearchManager();
			break;
			default:
				System.out.println("Invalid entry...");
				go();
		}
	}
		
	private void getDocuments()
	{
		doc.getDocuments();
		go();
	}
}
